<#import "../template.ftl" as t/>
<@t.html ; part>
    <#if part="head">
        <link href="<@spring.url "/resources/plugins/datatables/dataTables.bootstrap.css"/>" rel="stylesheet">
        <link href="<@spring.url "/resources/plugins/datatables/responsive.dataTables.min.css"/>" rel="stylesheet">
    </#if>
    <#if part="body">
    <div class="panel" id="dataBody">
        <#include "page.ftl"/>
    </div>
    </#if>
    <#if part="modal">

    </#if>

    <#if part="foot_script">
        <script type="text/javascript">
            var currentClass = "";
            var currentColumn = "";
            var columnName = "";
            var sortType = 0;
            function search() {
                pageChange(1);
            }
            function pageChange(page) {
                var key = $("#input-search2").val();
                if (currentClass == "sorting_asc") {
                    sortType = 1;
                } else {
                    sortType = 0;
                }
                $.post('<@spring.url "/saleManage/page" />',
                        {searchText:key, columnName:currentColumn, sortType:sortType, page:page},
                        function (data) {
                            $("#dataBody").html(data);
                            if (currentClass == "sorting" || currentClass =="sorting_desc") {
                                $("#"+columnName).attr("class", "sorting_asc");
                            } else {
                                $("#"+columnName).attr("class", "sorting_desc");
                            }
                        });
            }

            function shortColumn(names, obj) {
                columnName = names;
                currentClass = $("#"+columnName).attr("class");
                if (currentClass == "sorting_asc") {
                    sortType = 1;
                } else {
                    sortType = 0;
                }
                var key = $("#input-search2").val();
                if (columnName == "bangStatus") {
                    currentColumn = "bang_status";
                } else if (columnName == "voltageStep") {
                    currentColumn = "voltage_step";
                } else if (columnName == "elecConsumption") {
                    currentColumn = "elec_consumption";
                } else if (columnName == "types") {
                    currentColumn = "types";
                } else if (columnName == "relatedAt") {
                    currentColumn = "related_at";
                }else if (columnName == "saleName") {
                    currentColumn = "saleName";
                }
                $.post('<@spring.url "/saleManage/page" />',
                        {searchText:key, columnName:currentColumn, sortType:sortType, page:1},
                        function (data) {
                            $("#dataBody").html(data);
                            if (sortType == 0) {
                                $("#"+columnName).attr("class", "sorting_asc");
                            } else {
                                $("#"+columnName).attr("class", "sorting_desc");
                            }
                        });
            }
        </script>
    </#if>
</@t.html>